
:: TEST FRAMEWORK
@echo off
:: -- Prepare the Command Processor --

SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION 

:: -- Version History �
::         XX.XXX        YYYYMMDD Author Description

SET version=01.000-beta &:20051201 p.h.   initial version, providing the framework
SET version=01.000      &:20051202 p.h.   framework ready
:: !! For a new version entry, copy the last entry down and modify Date, Author and Description

SET version=%version: =% 

:: -- Set the title

SET title=%~nx0 - version %version%
TITLE %title% 

:: -- Do something useful

echo. -----------------------------------------------------
echo. ------------ Test Framework for Partition -----------
echo. -----------------------------------------------------
echo.

IF "%1"=="/?" goto Help
IF "%1"=="" goto Help
IF "%1"=="simple" goto SimpleTests
IF "%1"=="jar" goto CreateJar
IF "%1"=="student" goto RunStudent
IF "%1"=="all" goto RunAll
IF "%1"=="run" goto JustRun
IF "%1"=="all-no-compile" goto RunAllNoCompile
IF "%1"=="germany" goto RunTimes
IF "%1"=="multiple" goto RunMultiple
IF "%1"=="syntax" goto RunSyntax
goto Help

goto:EOF
:Help
echo. usage: %0 simple  	-^> starts simple quick tests.
echo.	%0 jar		-^> create new jar-file.
echo.	%0 student		-^> runs student tests from testsuite.
echo.	%0 all		-^> runs spice, speed and crack tests.
echo.	%0 run		-^> just run the program.
echo.	%0 all-no-compile	-^> run all and not compile (use existing jar).
echo.	%0 germany number	-^> run germany number of times.
echo.	%0 multiple	-^> run multiple tests.
echo.	%0 syntax		-^> run syntax tests.
goto:EOF

:RunTimes

call:CreateJar
echo.
echo running on germany.xml
echo. ----------------------------------------

call:TimeTestStart

FOR /L %%a IN (1,1,%2) DO (
call:germany germany 666
)

echo.
echo.
call:TimeTestEnd

goto:EOF

:germany

java -classpath bin\ main.Main tests\%~1.xml >NUL

IF %~2==%errorlevel% GOTO germany0
goto germany1
goto cmp_output%errorlevel%
:germany0
echo/|set /p =.
goto germany_end
:germany1
echo.
echo -------------^>ERROR
echo their: %~2 our: %errorlevel%
echo.
goto germany_end
:germany_end 

goto:EOF

:JustRun

echo. JUST RUNNING ...
java -classpath bin\ main.Main

goto:EOF

:RunAllNoCompile
call:SwitchToTestsuite

"java.exe" -jar testsuite.jar --spice np.jar
"java.exe" -jar testsuite.jar --speed np.jar
"java.exe" -jar testsuite.jar --crack np.jar
goto:EOF

:RunSyntax

call:CreateJar
call:SwitchToTestsuite

"java.exe" -jar testsuite.jar --syntax np.jar

goto:EOF

:RunMultiple

call:CreateJar
call:SwitchToTestsuite

"java.exe" -jar testsuite.jar --multiple np.jar

goto:EOF

:RunAll

call:CreateJar
call:SwitchToTestsuite

"java.exe" -jar testsuite.jar --spice np.jar
"java.exe" -jar testsuite.jar --speed np.jar
"java.exe" -jar testsuite.jar --crack np.jar

goto:EOF

:RunStudent

call:CreateJar
call:SwitchToTestsuite

"java.exe" -jar testsuite.jar --student np.jar

goto:EOF

:SwitchToTestsuite

echo. --------------------------------------------
echo. --------  Open TESTSUITE... ----------------
echo. --------------------------------------------
cd testsuite

goto:EOF

:: Create jar-file
:CreateJar
echo COMPILING java files...
echo.
:: set the environment variable to your C:\Program Files\Java\jdk1.6.0_21\bin
"javac.exe" -Xlint:unchecked -classpath ./bin -d ./bin src/main/*.java
"javac.exe" -Xlint:unchecked -classpath ./bin -d ./bin src/worker/*.java
echo.
echo CREATING Jar-file...
echo.
:: set the environment variable to your C:\Program Files\Java\jdk1.6.0_21\bin
"jar.exe" cmf  manifest.txt np.jar -C ./bin main
"jar.exe" uf  np.jar -C ./bin worker
echo Copying JAR to testsuite folder...
copy np.jar testsuite\

goto:EOF

:: ------- Simple TEST
:SimpleTests

::first create the new jar
call:CreateJar

echo.
echo Starting simple tests...
echo. ----------------------------------------
call:simple graph00 3
call:simple GraphausderVorlesung_8 8
call:simple 4sequential_5 5
call:simple 10sequential_11 11
call:simple 50sequential_51 51
call:simple 200by4threads_801 801
call:simple 500sequential_501 501
call:simple Energienetz8 8
call:simple Neuschleswegien13 13
call:simple parser_test_3 3
call:simple graph00_a 2
call:simple germany 666
call:simple EliaSand_generated_145 145
call:simple EliaSand_generated_305 305
call:simple Milchstrasse_generated_81 81
call:simple Milchstrasse_generated_86 86
call:simple Milchstrasse_generated_100 100
call:simple Milchstrasse_generated_3708 3708
call:simple Milchstrasse_generated_4708 4708
call:simple milliongraph_1 1
call:simple 5000sequential_5001 5001
call:simple Galaxie_generated_6589 6589
call:simple Atom_50000Knoten_100000Kanten_43546 43546

goto:EOF

:simple
echo.
echo testing %~1.xml

call:TimeTestStart
rem java -classpath bin\ main.Main tests\%~1.xml >NUL
java -jar np.jar tests\%~1.xml >NUL
call:TimeTestEnd
:: >tests\%~1.txt

IF %~2==%errorlevel% GOTO cmp_output0
echo their: %~2 our: %errorlevel%
goto cmp_output1
@fc tests\%~1.txt tests\%~1.ref.txt >NUL
goto cmp_output%errorlevel%
:cmp_output0
echo success
goto simple_end
:cmp_output1
echo -------------^>ERROR
goto simple_end
:simple_end 

goto:EOF


:TimeTestStart

rem The format of %TIME% is HH:MM:SS,CS for example 23:59:59,99
set STARTTIME=%TIME%

goto:EOF

:TimeTestEnd

set ENDTIME=%TIME%

rem output as time

rem echo STARTTIME: %STARTTIME%
rem echo ENDTIME: %ENDTIME%

rem convert STARTTIME and ENDTIME to centiseconds
set /A STARTTIME=(1%STARTTIME:~0,2%-100)*360000 + (1%STARTTIME:~3,2%-100)*6000 + (1%STARTTIME:~6,2%-100)*100 + (1%STARTTIME:~9,2%-100)
set /A ENDTIME=(1%ENDTIME:~0,2%-100)*360000 + (1%ENDTIME:~3,2%-100)*6000 + (1%ENDTIME:~6,2%-100)*100 + (1%ENDTIME:~9,2%-100)

rem calculating the duratyion is easy
set /A DURATION=%ENDTIME%-%STARTTIME%

rem we might have measured the time inbetween days
if %ENDTIME% LSS %STARTTIME% set set /A DURATION=%STARTTIME%-%ENDTIME%

rem now break the centiseconds down to hors, minutes, seconds and the remaining centiseconds
set /A DURATIONH=%DURATION% / 360000
set /A DURATIONM=(%DURATION% - %DURATIONH%*360000) / 6000
set /A DURATIONS=(%DURATION% - %DURATIONH%*360000 - %DURATIONM%*6000) / 100
set /A DURATIONHS=(%DURATION% - %DURATIONH%*360000 - %DURATIONM%*6000 - %DURATIONS%*100)

rem some formatting
if %DURATIONH% LSS 10 set DURATIONH=0%DURATIONH%
if %DURATIONM% LSS 10 set DURATIONM=0%DURATIONM%
if %DURATIONS% LSS 10 set DURATIONS=0%DURATIONS%
if %DURATIONHS% LSS 10 set DURATIONHS=0%DURATIONHS%

rem outputing
rem echo DURATION: %DURATION% in centiseconds
echo duration: %DURATIONH%:%DURATIONM%:%DURATIONS%,%DURATIONHS%

goto:EOF


:: -------- END OF APPLICATION ----------

REM.-- End of application
